﻿#include "ui_hmi.h"
#include "ui_ui_hmi.h"
#include "ui_setLocal.h"
#include <QDebug>

uiHmi::uiHmi(LocalDev *ld, QWidget *parent) :
    QWidget(parent),
    ui(new Ui::uiHmi)
{
    ui->setupUi(this);

    this->m_ld = ld;

    Hmi h = ld->getHmi();
    this->m_hmi = &h;

    ui->busy->setText(QString::number(m_hmi->busy()));
    ui->mode->setText(QString::number(m_hmi->mode()));
    ui->state->setText(QString::number(m_hmi->state()));
    ui->instruct->setText(QString::number(m_hmi->instruct()));
    ui->allowAutiSwi->setText(QString::number(m_hmi->allowAutiSwi()));
    ui->b4->setText(QString::number(m_hmi->b4()));
    ui->reset->setText(QString::number(m_hmi->reset()));
    ui->b5->setText(QString::number(m_hmi->b5()));
    ui->emrst->setText(QString::number(m_hmi->emrst()));
    ui->b6->setText(QString::number(m_hmi->b6()));
    ui->emergencyStop->setText(QString::number(m_hmi->emergencyStop()));
    ui->b7->setText(QString::number(m_hmi->b7()));
    ui->enginnerAuth->setText(QString::number(m_hmi->enginnerAuth()));
    ui->cmd->setText(QString::number(m_hmi->cmd()));
    ui->x->setText(QString::number(m_hmi->x()));
    ui->y->setText(QString::number(m_hmi->y()));
    ui->z->setText(QString::number(m_hmi->z()));
}

uiHmi::~uiHmi()
{
    delete ui;
}

void uiHmi::on_setCluster_clicked()
{
    qDebug() << "设置就地控制器";

    uiSetLocal * Local = new uiSetLocal(this->m_ld);
    Local->setWindowModality(Qt::ApplicationModal);
    Local->setGeometry(this->x() + 10, this->y() + 10, Local->width(), Local->height());

    connect(Local, &uiSetLocal::setLocal, [=](QString xml){
        emit setLocal(xml);

        this->close();
        this->deleteLater();
    });

    Local->show();

}
